#include <bits/stdc++.h>

using namespace std;
map<long long, long long>s;
const int N = 2e5 + 10;
long long a[N];
int main() {
	int T;
	cin >> T;
	while (T--) {
		int n;
		cin >> n;
		long long sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			sum += a[i];
			s[a[i]] ++;
		}
	//	cout << sum * 2 << " " << (long long) sum * 2<<endl;
		if (2 * sum % n != 0)cout << 0 << endl;
		else {
		long long ans = 0;
		long long need = 2 * sum / n;
		for (int i = 0; i < n; i++) {
			int sum1 = need - a[i];
			if(sum1 == a[i])ans += s[sum1] - 1;
			else ans += s[sum1];
		}
		cout << ans / 2 << endl;
		}
		s.clear();
	}
}
